﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZedGraph;
using System.Drawing;

namespace PermonAnalizer
{
    class CPUGraph
    {

        private ZedGraphControl zgc;
        private List<DataPoint> dataPoints;

        public CPUGraph(ZedGraphControl z, List<DataPoint> d)
        {
            zgc = z;
            dataPoints = d;
        }

        public void CreateCPUGraph()
        {

            GraphPane myPane = zgc.GraphPane;

            // Set the titles and axis labels
            myPane.Title.Text = "CPU % Analysis";
            myPane.XAxis.Title.Text = "Time";
            myPane.XAxis.Type = AxisType.Date;
            myPane.XAxis.Scale.MajorUnit = DateUnit.Hour;
            myPane.YAxis.Title.Text = "CPU %";


            // Make up some data points from the Sine function
            PointPairList _list1 = new PointPairList();

            int i2 = 0;
            if (dataPoints != null)
            {
                foreach (DataPoint point in dataPoints)
                {

                    _list1.Add( point.getXDate() , point.getValue() );

                }
            }
            // Generate a blue curve with Plus symbols,
            LineItem _myCurve1 = myPane.AddCurve("CPU %", _list1, Color.Blue, SymbolType.None);
            _myCurve1.Line.IsSmooth = true;
            _myCurve1.Line.SmoothTension = 0.5F;

            // Fill the pane background with a color gradient
            myPane.Fill = new Fill( Color.White, Color.FromArgb(220, 220, 255), 45F);

            //Make the MajorGrids of Axes visible
            myPane.XAxis.MajorGrid.IsVisible = true;
            myPane.YAxis.MajorGrid.IsVisible = true;
            myPane.YAxis.Scale.Min = 0;
            myPane.YAxis.Scale.Max = 100;

            // Calculate the Axis Scale Ranges
            zgc.AxisChange();
            zgc.Visible = false;
            zgc.Visible = true;

        }
    }
}
